<script setup>
import api from '@/api';
import utils from '@/utils';
import { onMounted, ref } from 'vue';

const sshTunnelId = ref('')
const emits = defineEmits(['cancel', 'submit'])

// handleCancle
function handleCancle() {
  emits('cancel')
}

// handleSave
async function handleSave() {
  if (!sshTunnelId.value) {
    utils.message.warning('请选择SSH隧道');
    return;
  }
  emits('submit', sshTunnelId.value)
}
// SSH主机选项
const sshTunnelOptions = ref([
]);
const search = async () => {
  const res = await api.sshTunnel.getSshTunnelList();
  sshTunnelOptions.value = res.data;
};

onMounted(search);

</script>

<template>

  <el-form label-width="auto">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="" prop="sshHostId">
          <el-radio-group v-model="sshTunnelId">
            <el-radio v-for="item in sshTunnelOptions" :key="item.id" :label="item.id">{{ `${item.name}
              ${item.username}@${item.host}:${item.port}` }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>

  <div class="dialog-footer">
    <el-button @click="handleCancle">取消</el-button>
    <el-button type="primary" @click="handleSave">确定</el-button>
  </div>
</template>

<style scoped lang="scss"></style>
